<?php
$odd_detail = Frontend::findOddByMacth((int) $feed_id);
$match_detail = Frontend::findMatchById((int) $feed_id);
$user_odd = Frontend::findUserOddByMatchId((int) $feed_id);
$count = 0;
?>
<div class="span12">
    <div data-event-status="notstarted" data-event-id="182" class="event-heading">
        <div class="event-info clearfix">
            <?php
            foreach ($match_detail as $_match_detail) {
                $time = $_match_detail["DateMatchTS"];
                $team1 = Frontend::findTeamById((int) $_match_detail["Team1"]);
                $team2 = Frontend::findTeamById((int) $_match_detail["Team2"]);
                ?>
                <div class="team home">
                    <h1>
                        <img width="60" class="logo pull-left" src="<?php echo SKIN_FPATH ?>skin/frontend/img/icon-no-image-512.png">
                        <?php
                        foreach ($team1 as $_team1) {
                            echo $_team1["name"];
                        }
                        ?>   
                        <!--<span title="" class="label label-inverse team-standing" rel="tooltip" data-original-title="Thứ hạng">13</span>-->
                    </h1>
                </div>
                <div class="result">
                    <h1 class="r"> <?php echo $_match_detail["Result"]; ?> </h1>
                </div>
                <div class="team away">
                    <h1>
                        <?php
                        foreach ($team2 as $_team2) {
                            echo $_team2["name"];
                        }
                        ?>                                          
                        <!--<span title="" class="label label-inverse team-standing" rel="tooltip" data-original-title="Thứ hạng">7</span>-->
                        <img style="float: right" width="60" class="logo pull-right" src="<?php echo SKIN_FPATH ?>skin/frontend/img/icon-no-image-512.png">
                    </h1>
                </div>
            <?php } ?>
        </div>
        <div class="event-meta">
            <?php
            $total_money = 0;
            foreach ($user_odd as $_user_odd) {
                $total_money = $total_money + $_user_odd["money"];
            }
            ?>
            <div>
                <img src="<?php echo SKIN_FPATH ?>skin/frontend/icon/Flaticon_4076.png"/> <?php echo date("h:i", $time); ?> , <?php echo date("D", $time); ?>, <?php echo date("d/m/Y", $time); ?>            
            </div>
            <div>
                <img src="<?php echo SKIN_FPATH ?>skin/frontend/icon/people.png"/> <?php if(iterator_to_array($user_odd)==null){ echo "0"; }else{ echo count($user_odd); } ?> người chơi
            </div>
            <div>
                <img src="<?php echo SKIN_FPATH ?>skin/frontend/icon/money.png"/> <?php echo $total_money ?> điểm đặt
            </div>
            <div class="pull-right" style="margin-right: 0;">
                <div class="fb-like" data-href="http://dudoanthethao.com.vn" data-colorscheme="light" data-layout="button_count" data-action="like" data-show-faces="true"></div>
            </div>
        </div>
    </div>
</div>

<div class="span12">
    <?php
    $ceil_value = ceil(count($arr_odd_bets["ODD_BETS"]) / 3);
    for ($i = 0; $i < $ceil_value; $i++) {
        ?>
        <div class="row">
            <?php
            foreach ($arr_odd_bets["ODD_BETS"] as $key => $_arr_odd_bets) {
                foreach ($odd_detail as $_odd_detail) {
                    if ($key == $_odd_detail["typeID"]) {
                        $value = explode("|", $_odd_detail["value"]);
                        $title = $_odd_detail["title"];
                        ?>
                        <div class="span4">
                            <table class="table table-bordered table-heading table-game">
                                <thead>
                                    <tr class="heading">
                                        <th colspan="<?php echo count($arr_odd_bets["ODD_BETS"][$key]); ?>">
                                            <a href="" title="<?php echo $title; ?>">
                                                <img src="<?php echo SKIN_FPATH ?>skin/frontend/icon/schedule.png"/>
                                                <?php echo $title; ?>
                                            </a>
                                        </th>
                                    </tr>
                                    <tr class="title">
                                        <?php foreach ($arr_odd_bets["ODD_BETS"][$key] as $_title) {
                                            ?>
                                            <th>
                                                <a href="#">
                                                    <?php echo $_title; ?>
                                                </a>
                                            </th>
                                        <?php } ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $number = ceil((count($value) - 1) / count($arr_odd_bets["ODD_BETS"][$key]));
                                    $_count = 0;
                                    for ($j = 0; $j < $number; $j++) {
                                        ?>
                                        <tr>
                                            <?php
                                            foreach ($value as $_key => $_value) {
                                                $data = array('id' => $_odd_detail['_id'], 'value' => $_value, 'time' => $_match_detail['DateMatchTS'], 'index_key' => $_key);
                                                $encode = json_encode($data);
                                                $base_encode = base64_encode($encode);
                                                if ($_value != "") {
                                                    if ($_count > 0) {
                                                        if ($_count % count($arr_odd_bets["ODD_BETS"][$key]) == 0) {
                                                            $_count = 0;
                                                            break;
                                                        }
                                                    }
                                                    ?>
                                                    <td>
                                                        <?php if ($_arr_odd_bets[$_count] == "Tỷ Lệ" || $_value == "chưa có tỷ lệ") { ?>
                                                            <span class="label label-inverse"><?php echo $_value; ?></span>
                                                        <?php } else { ?>
                                                            <a href="javascript:void(0)" onclick="addodd('<?php echo $base_encode; ?>');" class="add-to-betslip"><?php echo $_value; ?></a>
                                                        <?php } ?>

                                                    </td>
                                                    <?php
                                                    $_count++;
                                                    unset($value[$_key]);
                                                }
                                            }
                                            ?>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                        <?php
                        break;
                    } else {
                        ?>

                        <?php
                    }
                }
                $count++;
                unset($arr_odd_bets["ODD_BETS"][$key]);
                if ($count % 3 == 0) {
                    break;
                }
            }
            ?>
        </div>
    <?php } ?>
</div>